Ext.namespace("Task.ExecuteStatus");

Task.ExecuteStatus.panel = function() {
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	};
	this.renderDispatcher = function(s, m, rec){
		var taskname = rec.get("USER_NAME");
		var taskname2 = rec.get("EXECUTOR");
		//var dispatchType  =rec.get("TASK_EXE_PERFORM_TYPE");
		return taskname2+"-->"+taskname;

	};
	this.renderRemindWay = function(s, m, rec){
		var taskStatus = rec.get("TASK_EXE_STATUS");
		if(taskStatus==3){
			return "<img src='../resources/icons/stop.png' title='已完成不用催办'></img>";
		}else{
			return "<img src='../resources/icons/feed_document.png' style='cursor:hand' title='催办'></img>";
		}
	};
	this.exeId;
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../task/searchTaskExeStatus.form?timesnap=' +new Date().getTime()
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			fields: ['TASK_ID','TASK_TITLE', 'TASK_DATE', 'TASK_COMPLETE_DATE','USER_NAME','EXECUTOR','TASK_EXE_STATUS','TASK_EXE_PERFORM_TYPE','TASK_EXE_USER_ID']
		}),listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	          	taskId:this.exeId
       	          });    
              },
              scope:this 
	    	}
		}
	});
	var delTaskUploadFile = new Ext.data.Connection({
		url:'../task/delTaskUploadFile.form?timesnap=' + new Date().getTime(),
		method:'post'
	});
	this.colModel = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
			{header: 'TASK_ID', width: 50, hidden: true, dataIndex: 'TASK_ID'},
			{header: '任务名称', width: 200, dataIndex: 'TASK_TITLE'},
			{header: '开始时间', width: 100, dataIndex: 'TASK_DATE'},
			{header: '完成时间',width: 100, dataIndex: 'TASK_COMPLETE_DATE'},
			{header: '执行人',width: 200, dataIndex: 'USER_NAME',renderer:this.renderDispatcher},
			{header: '状态',width: 50, dataIndex: 'TASK_EXE_STATUS',renderer:this.renderTaskStatus},
			{header: '催办',width: 50, dataIndex: 'TASK_EXE_USER_ID',renderer:this.renderRemindWay}
	    ]
	});
	
	this.gridPanel = new Ext.grid.GridPanel({
		region: 'center',
		cm:this.colModel,
		store:this.store,
		stripeRows: true, 
		sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 10,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        viewConfig: { forceFit: true },
        listeners:{
        	cellclick:function (grid, rowIndex, columnIndex, e) {
	    		if(columnIndex==6){
	    			var record = grid.getStore().getAt(rowIndex);
	        		var user_id = record.get("TASK_EXE_USER_ID");
	        		var task_id = record.get("TASK_ID");
	        		var task_title = record.get("TASK_TITLE");
	        		var taskStauts = record.get("TASK_EXE_STATUS");
	        		if(taskStauts==3)
	        			return false;
	    			if(this.winMsg==null){
		    				this.winMsg=new Message.Msg(function(){
		    					var remindWay = this.txtRemind;
		    					var url='../task/sentMessage.form?timesnap=' + new Date().getTime();
		    					Utils.request(url,{
				        			params:{
				        			user_id:user_id,
				        			task_id:task_id,
				        			task_title:task_title,
				        			remindWay:remindWay
				        			},
				        			success:function(){
				        				Utils.info('发送成功！');
				        			}
				        		});
		    				},'请选择你要催办的提醒方式','1');
	    			}
		    		this.winMsg.show();
	    			
	    		}else{
	    			return false;
	    		}
        	} 
        }
	});
	Task.ExecuteStatus.panel.superclass.constructor.call(this, {
		title:'执行情况',
		layout:'border',
		items:[this.gridPanel],
		listeners:{
			render:this.queryUpfile,
			activate:this.queryUpfile
		}
	});
};
Ext.extend(Task.ExecuteStatus.panel, Ext.Panel, {
	initFeedBack:function(exeId){
		this.exeId = exeId;
	},
	queryUpfile :function(exeId){
		this.store.load({
			params:{
				start : 0,
				limit : 10,
				taskId:this.exeId
			}
		});
	},
	downloadUrl :function(s, m, rec){
		return "<a href='../task/downloadFile.form?fileId="+s+"'>下载</a>";
	},
	showSubmit:function(wm){
		//var url='../task/sentMessage.form?timesnap=' + new Date().getTime();
		var remind=wm.txtRemind;	
		alert(this.remind);
		//this.submitPlan(url);
	}
});


